package main

/**
素数的获取
*/
import (
	"flag"
	"fmt"
	"os"
	"strconv"
)

var goalb int

func primes(c chan int) {
	p := <-c

	if p > goalb {
		os.Exit(0)
	}
	fmt.Println(p)

	nc := make(chan int)

	go primes(nc)

	for {
		i := <-c
		if i%p != 0 {
			nc <- i
		}
	}
}

func main() {
	flag.Parse()

	args := flag.Args()

	if args != nil && len(args) > 0 {
		_, err := strconv.Atoi(args[0])
		if err != nil {
			goalb = 100
		}
	} else {
		goalb = 100
	}
	fmt.Println("goalb=", goalb)

	c := make(chan int)

	go primes(c)

	for i := 2; ; i++ {
		c <- i
	}
}
